package com.niit.service.impl;

import java.util.List;

import com.niit.bean.Admin;
import com.niit.dao.AdminDao;
import com.niit.dao.impl.AdminDaoImpl;
import com.niit.service.AdminService;
import com.niit.utils.Page;

public class AdminServiceImpl implements AdminService {
	
	private AdminDao dao = new AdminDaoImpl();
	
	@Override
	public int add(Admin t) {
		return dao.add(t);
	}

	@Override
	public int delete(Admin t) {
		return dao.delete(t);
	}

	@Override
	public int update(Admin t) {
		return dao.update(t);
	}

	@Override
	public Page<Admin> getPage(String pagenum, String url) {
		int total = dao.findTotal();//查出总记录数
		Page<Admin> page = null;
		if(pagenum == null){
			page = new Page<Admin>(total,1);
		}else{
			page = new Page<Admin>(total, Integer.parseInt(pagenum));
		}
		List<Admin> list = dao.findAll(page.getStartIndex(), page.getEndIndex());
		page.setList(list);
		page.setUrl(url);
		return page;
	}

	@Override
	public boolean usernameExist(String username) {
		boolean flag = dao.usernameExist(username);
		return flag;
	}

	@Override
	public boolean login(Admin admin) {
		return dao.login(admin);
	}

	@Override
	public List<Admin> findAll() {
		int last = dao.findTotal();
		List<Admin> list = dao.findAll(0, last);
		return list;
	}

}
